// Originally found in Jonny Stutters
// http://jeremah.co.uk/blog/permalink/a_low_pass_filter_in_processing

import lll.Loc.*;

class LowPassAvg {
    LinkedList buffer;
    int len;

    LowPassAvg(int len) {
        this.len = len;
        buffer = new LinkedList();
        for(int i = 0; i < len; i++) {
            buffer.add(new Loc());
        }
    }

    Loc filter(Loc v) {
        buffer.add(v);
        buffer.removeFirst();
        Loc sum = new Loc();
        for(int i=0; i< buffer.size(); i++) {
                Loc fv = (Loc) buffer.get(i);
                sum.x += fv.x;
                sum.y += fv.y;
                sum.z += fv.z;
        }
        return sum.div(buffer.size());
    }
}
